package com.api.oa.mapper;

import com.api.oa.model.entity.YQMedCare;
import com.api.oa.model.vo.OaNoticeVo;
import com.api.oa.model.vo.YQMedCareVO;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
@Mapper
public interface YQMedCareMapper {

    @Insert("insert into  yq_med_care  (" +
        "medName," +
        "medSex," +
        "medFace," +
        "medIdCard," +
        "medPhone," +
        "medRole," +
        "medIns," +
        "medCert," +
        "medCertCode," +
        "disabled," +
        "createdAt" +
    ") " +
    "values " +
    "(" +
        "#{entity.medName}," +
        "#{entity.medSex}," +
        "#{entity.medFace}," +
        "#{entity.medIdCard}," +
        "#{entity.medPhone}," +
        "#{entity.medRole}," +
        "#{entity.medIns}," +
        "#{entity.medCert}," +
        "#{entity.medCertCode}," +
        "#{entity.disabled}," +
        "#{entity.createdAt}" +
    ")" )
    Integer insert(@Param("entity") YQMedCare entity);



    @Update("update  yq_med_care  set " +
        "medName = #{entity.medName}," +
        "medSex = #{entity.medSex}," +
        "medFace = #{entity.medFace}," +
        "medIdCard = #{entity.medIdCard}," +
        "medPhone = #{entity.medPhone}," +
        "medRole = #{entity.medRole}," +
        "medIns = #{entity.medIns}," +
        "medCert = #{entity.medCert}," +
        "medCertCode = #{entity.medCertCode}," +
        "disabled = #{entity.disabled}" +
    " where medIdCard = #{entity.medIdCard}")
    Integer update(@Param("entity") YQMedCare  entity);


    @Delete("delete from yq_med_care where medIdCard=#{id}")
    void delete(@Param("id") String id);


    @Select("select * from  yq_med_care  where noticeId = #{id}")
    List<YQMedCare> list(@Param("id") Long pid);



    @Select("<script>select * from  v_yq_care_user  <where> 1 = 1 " +
            "<if test='id!=null and id!=\"\"'> and concat(ifnull(medIdCard,''),ifnull(medName,''),ifnull(medPhone,'')) like concat('%',#{id},'%') </if>" +
            "<if test='insCode!=null and insCode!=\"\"'> and medIns = #{insCode}</if> " +
            "<if test='medRole!=null and  medRole!=\"\"'> and medRole = #{medRole} </if> </where> </script>")
    List<YQMedCareVO> page(@Param("id") String medIdCard, @Param("insCode") String insCode, @Param("medRole") String role);


    @Select("select * from  v_yq_care_user  where userId = #{id} limit 1")
    YQMedCare findOne(@Param("id") Long id);

    @Select("select * from  yq_med_care  where medPhone = #{medPhone} limit 1")
    YQMedCare findOneByPhone(@Param("medPhone") String phone);


    @Select("select * from  yq_med_care  where medIdCard = #{medIdCard} limit 1")
    YQMedCare findOneByIDCard(@Param("medIdCard") String idCard);

    @Select("<script> select * from  v_yq_care_user  where 1=1 <if test='insCode!=null and insCode!=\"\"'> and  medIns = #{insCode}</if> </script>")
    List<YQMedCareVO> queryMedByInsCode(@Param("insCode") String insCode);



    @Select("<script> select count(*) from yq_med_care where 1=1 <if test='insCode!=null and insCode!=\"\"'> and medIns = #{insCode}</if> </script>")
    Long count(@Param("insCode") String insCode);

}

